#!/bin/bash

# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'

echo -e "${CYAN}=== Kafka目录操作命令 ===${NC}"
echo "时间: $(date)"
echo "=================================="

# Kafka安装路径
KAFKA_HOME="/opt/module/kafka"

echo -e "${YELLOW}Kafka目录切换命令:${NC}"
echo ""

# 1. 切换到Kafka根目录
echo -e "${BLUE}1. 切换到Kafka根目录${NC}"
echo "cd $KAFKA_HOME"
echo "或"
echo "cd /opt/module/kafka"
echo ""

# 2. 切换到Kafka bin目录
echo -e "${BLUE}2. 切换到Kafka bin目录${NC}"
echo "cd $KAFKA_HOME/bin"
echo "或"
echo "cd /opt/module/kafka/bin"
echo ""

# 3. 切换到Kafka config目录
echo -e "${BLUE}3. 切换到Kafka config目录${NC}"
echo "cd $KAFKA_HOME/config"
echo "或"
echo "cd /opt/module/kafka/config"
echo ""

# 4. 切换到Kafka logs目录
echo -e "${BLUE}4. 切换到Kafka logs目录${NC}"
echo "cd $KAFKA_HOME/logs"
echo "或"
echo "cd /opt/module/kafka/logs"
echo ""

# 5. 检查当前目录
echo -e "${BLUE}5. 检查当前目录${NC}"
echo "pwd"
echo ""

# 6. 列出目录内容
echo -e "${BLUE}6. 列出目录内容${NC}"
echo "ls -la"
echo ""

echo -e "${YELLOW}常用Kafka操作命令:${NC}"
echo ""

# Kafka服务管理
echo -e "${GREEN}Kafka服务管理:${NC}"
echo "启动Kafka: $KAFKA_HOME/bin/kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties"
echo "停止Kafka: $KAFKA_HOME/bin/kafka-server-stop.sh"
echo "查看Kafka进程: jps | grep Kafka"
echo ""

# Kafka主题管理
echo -e "${GREEN}Kafka主题管理:${NC}"
echo "创建主题: $KAFKA_HOME/bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092 --partitions 3 --replication-factor 1"
echo "列出主题: $KAFKA_HOME/bin/kafka-topics.sh --list --bootstrap-server localhost:9092"
echo "查看主题详情: $KAFKA_HOME/bin/kafka-topics.sh --describe --topic test --bootstrap-server localhost:9092"
echo "删除主题: $KAFKA_HOME/bin/kafka-topics.sh --delete --topic test --bootstrap-server localhost:9092"
echo ""

# Kafka生产者/消费者
echo -e "${GREEN}Kafka生产者/消费者:${NC}"
echo "启动生产者: $KAFKA_HOME/bin/kafka-console-producer.sh --topic test --bootstrap-server localhost:9092"
echo "启动消费者: $KAFKA_HOME/bin/kafka-console-consumer.sh --topic test --from-beginning --bootstrap-server localhost:9092"
echo ""

# Kafka配置
echo -e "${GREEN}Kafka配置文件:${NC}"
echo "查看配置: cat $KAFKA_HOME/config/server.properties"
echo "编辑配置: vim $KAFKA_HOME/config/server.properties"
echo ""

# Kafka日志
echo -e "${GREEN}Kafka日志查看:${NC}"
echo "查看服务日志: tail -f $KAFKA_HOME/logs/server.log"
echo "查看控制器日志: tail -f $KAFKA_HOME/logs/controller.log"
echo ""

echo -e "${CYAN}==================================${NC}"
echo -e "${CYAN}Kafka目录操作命令完成${NC}" 